package serviceimpl;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;

import lib.ExecuteLocal;
import lib.JsonHelper;
import lib.MySQLLoaclHelper;

public class TiKU {

	public static void main(String[] args) throws IOException, SQLException {
		String reads = FileUtils.readFileToString(new File("D:\\tiku.txt"));
		List<Map<String,String>> questions = JsonHelper.fromString(reads, List.class, Map.class);
		List<Object[]> paramsList = new ArrayList<Object[]>();
		String sql = "insert into pre_plugin_tiku (question,`option`,answer,`explain`,pic,`type`,chapter,status,createtime) value(?,?,?,?,?,?,?,?,?)";
		long time = new Date().getTime();
		for (Map<String, String> map : questions) {
			if(map.get("option1")==null || map.get("option1").equals("")){
				map.put("option1", "A、对");
				map.put("option2", "B、错");
				if(map.get("answer")!=null && map.get("answer").equals("对")){
					map.put("answer","A");
				}else{
					map.put("answer","B");
				}
			}
			String option = String.format("{\"option1\":\"%s\",\"option2\":\"%s\",\"option3\":\"%s\",\"option4\":\"%s\"}", map.get("option1"),map.get("option2"),map.get("option3"),map.get("option4"));
			
			paramsList.add(new Object[]{map.get("question"),option,map.get("answer"),map.get("explain"),map.get("pic"),6,map.get("chapter"),1,time});
		}
		MySQLLoaclHelper.withTransaction(new ExecuteLocal() {
			
			@Override
			public void call() throws Exception {
				executeBatch(sql, paramsList);
			}
		});
	}
}

		